import 'package:flutter/animation.dart';
import 'package:flutter/material.dart';
import 'package:hi_flutter/animate/animated_logo.dart';
import 'package:hi_flutter/app_page.dart';

class AnimatePage3 extends StatefulWidget {
  const AnimatePage3({Key? key}) : super(key: key);

  @override
  AnimatePage3State createState() => AnimatePage3State();
}

class AnimatePage3State extends State<AnimatePage3>
    with SingleTickerProviderStateMixin {
  late AnimationController controller;
  late Animation<double> animation;

  @override
  initState() {
    super.initState();
    controller = AnimationController(
        duration: const Duration(milliseconds: 2000), vsync: this);
    animation = Tween(begin: 0.0, end: 300.0).animate(controller);

    animation.addStatusListener((status) {
      if (status == AnimationStatus.completed) {
        controller.reverse();
      } else if (status == AnimationStatus.dismissed) {
        controller.forward();
      }
    });
    controller.forward();
  }

  @override
  Widget build(BuildContext context) {
    return AppPage(
      body: AnimatedLogo(animation: animation),
    );
  }

  @override
  dispose() {
    controller.dispose();
    super.dispose();
  }
}
